var analisisClass = {
    layout: null,
    win: null,
    winLayout: null,
    winForm: null,
    grid_1: null,
    grid_2: null,
    statusGrid2: null,
    widTabPanel: function(){
        var me = this,
            disTab,
            tabTra;

        mainTab.addTab("tabAnalisis", "Grid's Analisis", "150px", "-1");
        disTab = mainTab.cells('tabAnalisis');
        me.layout = disTab.attachLayout('2U');
        mainTab.setTabActive("tabAnalisis");
    },
    widGrid1: function(){
        var me = this,
            statusGrid,
            cell = me.layout.cells('a');

        cell.setWidth('490');
        cell.fixSize(true, true);
        cell.showHeader();
        cell.setText('Listado Principal');

        statusGrid = cell.attachStatusBar();

        me.grid_1 = cell.attachGrid();
        me.grid_1.setHeader("id,Normas,Nivel,Depto.,Municipio,Registradas,Validadas,id_depto,id_tipo_doc,id_nivel,id_municipio");
        me.grid_1.setColTypes("ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro");
        me.grid_1.setColAlign("left,left,left,left,left,right,right,left,left,left,center");
        me.grid_1.enableMultiline(true);
        me.grid_1.setInitWidths("30,*,*,*,*,70,65,*,*,*,*");
        me.grid_1.setColumnColor("#E5E5E5");
        me.grid_1.setColumnHidden(1,true);
        me.grid_1.setColumnHidden(7,true);
        me.grid_1.setColumnHidden(8,true);
        me.grid_1.setColumnHidden(9,true);
        me.grid_1.setColumnHidden(10,true);
        me.grid_1.init();
        
        me.grid_1.load("index.php?r=normas/GetData1", function(){
            me.grid_1.groupBy(1);
            statusGrid.setText("Numero de Registros: "+me.grid_1.getRowsNum());
        },"json");        
    },
    widGrid2: function(){
        var me = this,
            cell = me.layout.cells('b');

        cell.fixSize(true, true);
        cell.showHeader();
        cell.setText('Normas Registradas');

        me.statusGrid2 = cell.attachStatusBar();

        me.grid_2 = cell.attachGrid();
        me.grid_2.setHeader("id,Ley,Nro_ley,Objeto,Progmul.,Gestion,Val,Val2,Archivo");
        me.grid_2.setColTypes("ro,ro,ro,ro,ro,ro,ro,ro,ro");
        me.grid_2.setColAlign("right,right,right,left,center,center,center,left,center");
        me.grid_2.enableMultiline(true);
        me.grid_2.setInitWidths("30,50,55,*,80,80,50,*,*");
        me.grid_2.setColumnColor("#E5E5E5");
        me.grid_2.setColumnHidden(5,true);
        me.grid_2.setColumnHidden(7,true);
        me.grid_2.setColumnHidden(8,true);
        me.grid_2.customGroupFormat = function(text, count) {
            return "Gestión: " + text + " (" + count + " registros)";
        };
        me.grid_2.init();
    },
    onEventClickGrids: function(){
        var me = this,
            id_depto,
            id_tipod,
            id_nivel,
            id_munic;

        me.grid_1.attachEvent('onRowDblClicked', function (id, ind) {
            me.grid_2.clearAll();
            id_depto = me.grid_1.cells(id, 7).getValue()
            id_tipod = me.grid_1.cells(id, 8).getValue()
            id_nivel = me.grid_1.cells(id, 9).getValue()
            id_munic = me.grid_1.cells(id, 10).getValue()
            me.grid_2.load("index.php?r=normas/getData2&id_tipo_doc="+id_tipod+"&id_nivel="+id_nivel+"&id_depto="+id_depto+"&id_municipio="+id_munic, function(){
                me.grid_2.groupBy(5);
                me.statusGrid2.setText("Numero de Registros: " + me.grid_2.getRowsNum());
            }, "json");
        });
        me.grid_2.attachEvent('onRowDblClicked', function (id, ind) {
            analisisClass.widWindow();
            analisisClass.widFormWindow();
            analisisClass.widGridWindow();
        });
    },
    widWindow: function(){
        var me = this,
            windows = new dhtmlXWindows();

        me.win = windows.createWindow('window_1', 0, 0, 900, 475);
        me.win.setText('Normas Registradas');
        me.win.button('park').hide();
        me.win.button('minmax1').hide();
        me.win.denyResize();
        me.win.setModal(1);
        me.win.centerOnScreen();

        me.winLayout = me.win.attachLayout('2U');
    },
    widFormWindow: function(){
        var me = this,
            cell = me.winLayout.cells('a');

        cell.setWidth('370');
        cell.hideHeader();
        var str = [
            { type:"settings" , labelWidth:90, inputWidth:250, position:"absolute" },
            { type:"select", name:"mun_dpto", label:"Objeto:", validate: "NotEmpty", labelAlign:"right", inputWidth:262, labelLeft:6, labelTop:15, inputLeft:98, inputTop:15  },
            { type:"select", name:"mun_dpto", label:"Tipo:", validate: "NotEmpty", labelAlign:"right", inputWidth:262, labelLeft:6, labelTop:40, inputLeft:98, inputTop:40  },
            { type:"select", name:"mun_dpto", label:"Competencia:", validate: "NotEmpty", labelAlign:"right", inputWidth:262, labelLeft:6, labelTop:65, inputLeft:98, inputTop:65  },
            { type:"input", name:"dep_codigo", label:"Nº de Articulos:", labelAlign:"right", inputWidth:100, labelLeft:6, labelTop:90, inputLeft:98, inputTop:90  },
            { type:"input", name:"dep_detalle", label:"Observación:", labelAlign:"right", validate: "NotEmpty", rows:3, inputWidth:258, labelLeft:6, labelTop:114, inputLeft:98, inputTop:114  },
            { type:"checkbox", label: "(1) Presupuestación", inputLeft:96, inputTop:172, labelLeft:114, labelTop:175, labelWidth:200 },
            { type:"checkbox", label: "(2) Endeudamiento", inputLeft:96, inputTop:192, labelLeft:114, labelTop:195, labelWidth:200 },
            { type:"checkbox", label: "(3) Fideicomisos y otros fondos", inputLeft:96, inputTop:212, labelLeft:114, labelTop:215, labelWidth:200 },
            { type:"checkbox", label: "(4) Salarios", inputLeft:96, inputTop:232, labelLeft:114, labelTop:235, labelWidth:200 },
            { type:"checkbox", label: "(5) Tributación", inputLeft:96, inputTop:252, labelLeft:114, labelTop:255, labelWidth:200 },
            { type:"checkbox", label: "(6) Contabilidad y Tesoro", inputLeft:96, inputTop:272, labelLeft:114, labelTop:275, labelWidth:200 },
            { type:"checkbox", label: "(7) Proyectos", inputLeft:96, inputTop:292, labelLeft:114, labelTop:295, labelWidth:200 },
            { type:"checkbox", label: "(8) Explotación de Recursos Naturales", inputLeft:96, inputTop:312, labelLeft:114, labelTop:315, labelWidth:250 },
            { type:"checkbox", label: "(9) Transferencias", inputLeft:96, inputTop:332, labelLeft:114, labelTop:335, labelWidth:200 },
            { type:"checkbox", label: "(10) Otros (SCG)", inputLeft:96, inputTop:352, labelLeft:114, labelTop:355, labelWidth:200 },
            { type:"checkbox", label: "Análisis Validado", inputLeft:96, inputTop:397, labelLeft:114, labelTop:400, labelWidth:200 },
            { type:"button", name:"save_btn", label:"Button", value:"Guardar", width:"75", inputWidth:75, inputLeft:285, inputTop:400  }
        ];
        me.winForm = cell.attachForm(str);
    },
    widGridWindow: function(){
        var me = this,
            cell = me.winLayout.cells('b');

        cell.fixSize(true, true);
        cell.showHeader();
        cell.setText('Título el Objecto');

        me.grid = cell.attachGrid();
        me.grid.setHeader("Id,Tipo,Competencia,Articulo,Observación");
        me.grid.setColTypes("ro,ro,ro,ro,ro");
        me.grid.setColAlign("right,left,left,left,left");
        me.grid.setInitWidths("30,*,*,*,*");
        me.grid.setColumnColor("#E5E5E5");
        me.grid.init();
    },
    main: function(){
        analisisClass.widTabPanel();
        analisisClass.widGrid1();
        analisisClass.widGrid2();
        analisisClass.onEventClickGrids();
    }    
};